package com.fanco.learn_datastruct_leetcode.designpattern.singleton.type6;

/**
 * 双重检查
 * 优点：既解决了线程安全问题，又有比较高的效率，同时解决了懒加载问题
 */
public class Singleton06 {
    public static void main(String[] args) {

    }
}

// 双重检查
class Singleton {
    private static volatile Singleton uniqueInstance;

    public Singleton() {}

    public static Singleton getUniqueInstance() {
        if (uniqueInstance == null) {
            synchronized (Singleton.class) {
                if (uniqueInstance == null) {
                    uniqueInstance = new Singleton();
                }
            }
        }
        return uniqueInstance;
    }
}
